package com.rgbgame.editor;

import processing.core.PImage;
import processing.core.PApplet;

/**
 * 
 */

abstract class UIDockWidget{

    public static final int NORMAL = 0;
    public static final int HOVER = 1;
    public static final int SELECTED = 2;

            /**
			 * 
			 */
			protected final PApplet pApplet;
    
            public float preferredWidgetWidth;//preferred width of widget - parent may overrule
			public float preferredWidgetHeight;//preferred height of widget
			public float normalWidgetWidth;//dimensions that parent has chosen
			public float normalWidgetHeight;
			public float widgetWidth;//actual drawn dimensions (taking into account scaling, etc.)
			public float widgetHeight;
			public float targetWidgetWidth;
			public float targetWidgetHeight;
			public PImage normalIcon;
			public PImage hoverIcon;
			public PImage selectedIcon;
			public String hoverText;
			protected int mode;
			public float x;
			public float y;
			private float drawnY;
			public UIDock parent;
			public float easeSpeed;
			public float drawnWidgetWidth;
			public float drawnWidgetHeight;
			public boolean selectedFlag;

			{
				easeSpeed = .3f;
				selectedFlag = false;
			}

			public UIDockWidget(PApplet pApplet, float w, float h, String hT, UIDock p){
				this.pApplet = pApplet;
				preferredWidgetWidth = w; normalWidgetWidth = w; widgetWidth = h;
				preferredWidgetHeight = h; normalWidgetHeight = h; widgetHeight = h;
				targetWidgetWidth = w;
				targetWidgetHeight = h;
				hoverText = hT;
				parent = p;
				x = 0;
				y = 0;
				drawnY=y;
				drawnWidgetWidth = w;
				drawnWidgetHeight = h;
				mode = NORMAL;

			}

			public abstract void onSelect();

			public void onHover(){
				mode = HOVER;
			}

			public void draw(){
				//This should be changed so that it draws a textured rectangle, since that might give better smoothing.
				//Otherwise, image sizes should be better chosen.
				//fill(255,255,255,100);
//				float imageDepth = (mode==HOVER)?10:0;
//				pushMatrix();
//				translate(imageDepth,0,imageDepth);
				if(selectedFlag){mode = SELECTED;}
				PImage drawnIcon = normalIcon;
				drawnY = (1.0f-easeSpeed)*drawnY+easeSpeed*y;
				if(mode== NORMAL){drawnIcon = normalIcon;}
//				popMatrix();
				if(mode== HOVER){drawnIcon=hoverIcon;this.pApplet.fill(255); this.pApplet.text(hoverText,x+widgetWidth+3,drawnY+widgetHeight/2.0f+7); this.pApplet.noFill();}
				if(mode== SELECTED){drawnIcon=selectedIcon;}//fill(255,255,255,150); text(hoverText,x+widgetWidth+3,drawnY+widgetHeight/2.0+7); noFill();}
				pApplet.image(drawnIcon,x,drawnY,drawnWidgetWidth,drawnWidgetHeight);
				//noFill();
				mode = NORMAL;
				drawnWidgetWidth = (1.0f-easeSpeed)*drawnWidgetWidth + easeSpeed*widgetWidth;
				drawnWidgetHeight = (1.0f-easeSpeed)*drawnWidgetHeight + easeSpeed*widgetHeight;
			}

			protected void selectMe(){
				parent.selectWidget(this);
				mode= SELECTED;
			}

		}